﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SWEN_HMS.Classes
{
    public class EncodingAndDecodingcs
    {
        public string Encode(string sData)
        {
            try
            {
                byte[] Endatabytes = new byte[sData.Length];
                Endatabytes = System.Text.Encoding.UTF8.GetBytes(sData);
                string encodedData = Convert.ToBase64String(Endatabytes);
                return encodedData;
            }
            catch (Exception ex)
            {
                throw new Exception(" Error in Encode " + ex.Message);
            }

        }
        public string Decode(string sData)
        {
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();
            byte[] todecode = Convert.FromBase64String(sData);
            int CharCount = utf8Decode.GetCharCount(todecode, 0, todecode.Length);
            char[] decodedChar = new char[CharCount];
            utf8Decode.GetChars(todecode, 0, todecode.Length, decodedChar, 0);
            string result = new String(decodedChar);
            return result;


        }
    }

}